package com.secf.service.port.hpy.hys.test.day5;

import java.util.Arrays;

/**
 * @Author luoYong
 * @Date 2024-08-13 17:42
 */

public class DataAnalysis {
    public static void main(String[] args) {
        int[] data = generateData(1000000);

        long sum = calculateSum(data);
        System.out.println("Sum of data: " + sum);

        int max = findMax(data);
        System.out.println("Max value: " + max);

        long startTime = System.currentTimeMillis();
        Arrays.sort(data);
        long endTime = System.currentTimeMillis();
        System.out.println("Sorting time: " + (endTime - startTime) + " ms");
    }

    public static int[] generateData(int size) {
        int[] data = new int[size];
        for (int i = 0; i < size; i++) {
            data[i] = (int) (Math.random() * 1000);
        }
        return data;
    }

    public static long calculateSum(int[] data) {
        long sum = 0;
        for (int value : data) {
            sum += value;
        }
        return sum;
    }

    public static int findMax(int[] data) {
        int max = data[0];
        for (int value : data) {
            if (value > max) {
                max = value;
            }
        }
        return max;
    }
}
